<template>
	<view class="profile-container">
		<view class="user-info">
			<view class="avatar-section">
				<image class="avatar" :src="userInfo.avatar || '../../static/avatar.png'" mode="aspectFill"></image>
				<text class="username">{{ userInfo.account || '未设置账户名' }}</text>
			</view>
			
			<view class="info-item">
				<text class="label">手机号:</text>
				<text class="value">{{ userInfo.phone || '未绑定' }}</text>
			</view>
			
			<view class="info-item">
				<text class="label">邮箱:</text>
				<text class="value">{{ userInfo.email || '未绑定' }}</text>
			</view>
		</view>
		
		<view class="menu-list">
			<view class="menu-item" @click="goToMyTickets">
				<text class="menu-text">我的工单</text>
				<text class="arrow-icon">></text>
			</view>
			
			<view class="menu-item" @click="editProfile">
				<text class="menu-text">编辑资料</text>
				<text class="arrow-icon">></text>
			</view>
			
			<view class="menu-item" @click="changePassword">
				<text class="menu-text">修改密码</text>
				<text class="arrow-icon">></text>
			</view>
			
			<view class="menu-item" @click="logout">
				<text class="menu-text logout-text">退出登录</text>
				<text class="arrow-icon">></text>
			</view>
		</view>
	</view>
</template>

<script>
	import { getUserInfo } from '../../utils/auth.js';
	
	export default {
		data() {
			return {
				userInfo: {}
			}
		},
		onLoad() {
			// 从本地存储获取真实的用户信息
			const userInfo = getUserInfo();
			if (userInfo) {
				this.userInfo = userInfo;
			} else {
				// 如果没有用户信息，使用默认值
				this.userInfo = {
					account: '访客',
					avatar: '../../static/avatar.png',
					phone: '未绑定',
					email: '未绑定'
				};
			}
		},
		methods: {
			goToMyTickets() {
				uni.navigateTo({
					url: '/pages/customer/my-tickets/my-tickets'
				})
			},
			editProfile() {
				uni.showToast({
					title: '编辑资料功能开发中',
					icon: 'none'
				})
			},
			changePassword() {
				uni.showToast({
					title: '修改密码功能开发中',
					icon: 'none'
				})
			},
			logout() {
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					success: (res) => {
						if (res.confirm) {
							// 清除用户信息
							uni.clearStorageSync();
							// 跳转到登录页面
							uni.redirectTo({
								url: '/pages/login/login'
							});
						}
					}
				})
			}
		}
	}
</script>

<style scoped>
	.profile-container {
		padding: 20rpx;
		background-color: #f5f5f5;
		min-height: 100vh;
	}
	
	.user-info {
		background-color: #fff;
		border-radius: 10rpx;
		padding: 40rpx 30rpx;
		margin-bottom: 20rpx;
	}
	
	.avatar-section {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 30rpx;
	}
	
	.avatar {
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
		margin-bottom: 20rpx;
	}
	
	.username {
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
	}
	
	.info-item {
		display: flex;
		justify-content: space-between;
		padding: 15rpx 0;
		border-bottom: 1rpx solid #eee;
	}
	
	.info-item:last-child {
		border-bottom: none;
	}
	
	.label {
		color: #666;
		font-size: 28rpx;
	}
	
	.value {
		color: #333;
		font-size: 28rpx;
	}
	
	.menu-list {
		background-color: #fff;
		border-radius: 10rpx;
		overflow: hidden;
	}
	
	.menu-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx;
		border-bottom: 1rpx solid #eee;
	}
	
	.menu-item:last-child {
		border-bottom: none;
	}
	
	.menu-text {
		font-size: 30rpx;
		color: #333;
	}
	
	.arrow-icon {
		color: #999;
		font-size: 30rpx;
	}
	
	.logout-text {
		color: #ff4d4f;
	}
</style>